package com.shopping.controller.front;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.shopping.commons.controller.BaseController;
import com.shopping.commons.response.MessageResp;
import com.shopping.model.ShopCar;
import com.shopping.param.ShopCarParam;
import com.shopping.response.UserResp;
import com.shopping.service.IShopCarService;

/**
 * 前台购物车的   Conroller
 * @author Administrator
 *
 */
@Controller
@RequestMapping("front/shopCar") 
public class FrontShopCarController extends BaseController{

	@Autowired
	private IShopCarService shopCarService;
	
	/**
	 * 增加购物车商品
	 * @param request
	 * @param param
	 * @return
	 */
	@RequestMapping("add/{id}")
	@ResponseBody  
	public MessageResp insert(HttpServletResponse response,HttpServletRequest request,@PathVariable("id")Integer commid){
		UserResp user=this.getUser(request);
		return shopCarService.add(response,request,user,commid);
	}
	
	/**
	 * 查询 用户
	 * @param request
	 * @param param
	 * @return
	 */
	@RequestMapping("select")
	@ResponseBody  
	public MessageResp select(HttpServletRequest request,ShopCarParam param){
		return shopCarService.select(param);
	}
	
	/**
	 * 删除用户   
	 * @param request
	 * @param param
	 * @return
	 */
	/*resetful 接口规范  接口编码的风格*/
	@RequestMapping(value="{id}",method=RequestMethod.DELETE)
	@ResponseBody 
	public MessageResp delete(HttpServletRequest request,@PathVariable("id") Integer id){
		return shopCarService.delete(id);
	}
	
	/**
	 * 修改用户
	 * @param request
	 * @param param
	 * @return
	 **/
	@RequestMapping("update")
	@ResponseBody 
	public MessageResp update(HttpServletRequest request,ShopCar param){
		return shopCarService.update(param);
	}
	
	/**
	 * 增加购物车商品
	 * @param request
	 * @param param
	 * @return
	 */
	@RequestMapping("toShopCar")
	@ResponseBody  
	public ModelAndView toShopCar(HttpServletRequest request,HttpServletResponse response){
		UserResp user=this.getUser(request);
		return shopCarService.toShopCar(request,response,user);
	}

}
